package com.ruoyi.bath.consumer.controller;

import java.util.List;

import com.ruoyi.bath.consumer.domain.Pay;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bath.consumer.domain.Consumer;
import com.ruoyi.bath.consumer.service.IConsumerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-07
 */
@RestController
@RequestMapping("/bath/consumer")
public class ConsumerController<payService> extends BaseController
{
    @Autowired
    private IConsumerService consumerService;

    //增加次数
    @RequestMapping("/count")
    public AjaxResult updateTimes(@RequestBody Consumer consumer){

        System.out.println("111111成功");
        return AjaxResult.success();
    }

    /**
     * 查询会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Consumer consumer)
    {
        startPage();
        List<Consumer> list = consumerService.selectConsumerList(consumer);
        return getDataTable(list);
    }

    /**
     * 导出会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:export')")
    @Log(title = "会员信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Consumer consumer)
    {
        List<Consumer> list = consumerService.selectConsumerList(consumer);
        ExcelUtil<Consumer> util = new ExcelUtil<Consumer>(Consumer.class);
        return util.exportExcel(list, "会员信息数据");
    }

    /**
     * 获取会员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(consumerService.selectConsumerById(id));
    }


    /**
     * 新增会员信息
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:add')")
    @Log(title = "会员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Consumer consumer, @RequestBody Pay pay)
    {
        int i = consumerService.insertConsumer(consumer);
        return toAjax(i);
    }

    /**
     * 修改会员信息
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:edit')")
    @Log(title = "会员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Consumer consumer)
    {

        consumerService.updateConsumer(consumer);
        return AjaxResult.success();

    }

    /**
     * 删除会员信息
     */
    @PreAuthorize("@ss.hasPermi('bath:consumer:remove')")
    @Log(title = "会员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consumerService.deleteConsumerByIds(ids));
    }
    //根据id增加次数
@PutMapping("/count")
    public AjaxResult updateCount(@RequestBody Consumer consumer){
        consumerService.updateCount(consumer);
        return AjaxResult.success();

}
}
